<!DOCTYPE html>

<html class="no-js">

<head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <title></title>
  <meta name="description" content="" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <script src="https://cdn.staticfile.org/axios/0.19.0-beta.1/axios.js"></script>
  <script src="../../cdn/vue/vue.global.min.js"></script>
  <link rel="stylesheet" href="../../cdn/element-plus/index.css" />
  <script src="../../cdn/element-plus/index.full.min.js"></script>
  <link rel="stylesheet" href="../../../lib/index.css" />
  <script src="../../../lib/avue.js"></script>
</head>

<body>
  <div id="app">
    {{obj}}
    <avue-form :option="option" v-model="obj"></avue-form>
  </div>
</body>
<script>
  var app = Vue.createApp({
    data() {
      return {
        items: [
          { label: 'type1Label1', value: 'type1Value1', type: 'type1' },
          { label: 'type1Label2', value: 'type1Value2', type: 'type1' },
          { label: 'type1Label3', value: 'type1Value3', type: 'type1' },
          { label: 'type2Label4', value: 'type2Value4', type: 'type2' },
          { label: 'type2Label5', value: 'type2Value5', type: 'type2' },
          { label: 'type2Label6', value: 'type2Value6', type: 'type2' },
          { label: 'type2Label7', value: 'type2Value7', type: 'type2' },
          { label: 'type3Label8', value: 'type3Value8', type: 'type3' },
          { label: 'type3Label9', value: 'type3Value9', type: 'type3' },
          { label: 'type3Label10', value: 'type3Value10', type: 'type3' },
          { label: 'type3Label11', value: 'type3Value11', type: 'type3' },
        ],
        obj: {
          type: 'type1', 
        },
        option: {
          labelWidth: 120,
          column: [
            {
              label: '一级类型',
              prop: 'type',
              type: 'select',
              span: 24,
              props: { label: 'label', value: 'value' },
              dicData: [{
                label: "类型1",
                value: 'type1'
              }, {
                label: "类型2",
                value: 'type2'
              }, {
                label: "类型3",
                value: 'type3'
              }],
              control: (val) => {
                let itemDicData = this.items;
                if (val) {
                  itemDicData = itemDicData.filter((o) => o.type === val);
                  if (this.items.length > 0 && !itemDicData.find((o) => o.value === this.obj.item)) {
                    this.obj.item = null;
                  }
                }
                const data = { item: { dicData: itemDicData } };
                return data;
              },
            },
            {
              label: '二级选项',
              prop: 'item',
              type: 'select',
              props: { label: 'label', value: 'value' },
              span: 24,
              dicData: this.items,
            },
          ]
        }
      }
    },
  })
  app.use(ElementPlus)
  app.use(AVUE)
  app.mount('#app')
</script>

</html>